﻿<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="x-ua-compatible" content="IE=8"/>
        <link rel="stylesheet" type="text/css" href="styles.css">
        <style type="text/css">
			html,body{padding:0;margin:0}		
            .container {
				font:caption;
				padding: 10px 10px;
				word-wrap: break-word;
				white-space: pre-wrap; 
			} 
			.line_name {
				font-weight: bold;
				text-align: center;
				padding: 10px 10px;
				word-wrap: break-word;
				white-space: pre-wrap; 
			} 
			#btn_container {
				padding:10px; background:THREEDFACE;
				border-top:1px solid THREEDFACE;
				position:absolute;bottom:0; right:0; left:0;
				text-align:center;
			}
			#div_text{ 
				padding-top:10px; padding-bottom:10px; 
				background:THREEDFACE;
			}			
            .button_ok { display:inline-block; } 
            .button_cancel { display:inline-block; } 
        </style>
        <title></title>
    </head>
    <body>
        <div id="div_text" class="container"></div>
		<div id="btn_container"> 
			<button id="btn_ok" class="button">Yes</button>	
			<button id="btn_cancel" class="button">No</button>
		</div>		
        <script>
			function getDPI() {
				var div = document.createElement('div');
				div.style.width = '1in';
				div.style.height = '1in';
				div.style.position = 'absolute';
				div.style.left = '-100%'; // 避免元素影响页面布局
				document.body.appendChild(div);
				var dpi = div.offsetWidth;
				document.body.removeChild(div);
				return dpi/96;
			}
            function close_window() {
                window.open('', '_self', '');
                window.close();
            }

            // parse data
            var parsed_args;
            var callback_fn;
            try {
                parsed_args = window.external.dialogArguments.toArray();
            }
            catch(e) {
            }
            if (parsed_args) {
                document.title = parsed_args[0];
				window.div_text.insertAdjacentHTML('beforeend',parsed_args[1]);
                var labelInnerHtml = window.btn_ok.innerHTML;
                window.btn_ok.innerHTML = parsed_args[2];//labelInnerHtml.replace(/Yes/g, parsed_args[2]);
                var labelInnerHtml = window.btn_cancel.innerHTML;
                window.btn_cancel.innerHTML = parsed_args[3];//labelInnerHtml.replace(/No/g, parsed_args[3]);				
                callback_fn = parsed_args[4];
            }

            // main script
			function resize(){	
				var dpi = Math.sqrt(getDPI()) * 1.15;
				var window_w = 400 * dpi;
				window_h = window.div_text.offsetHeight * dpi + window.btn_container.offsetHeight;
				window.resizeTo(window_w, window_h);
            }
			resize();
			document.onkeydown = function () {
				if (window.event.keyCode == 13 && window.document.activeElement.onclick) {
					window.document.activeElement.onclick();
				}
			};			
            window.btn_ok.onclick = function () {
                callback_fn && callback_fn("ok", true);
                close_window();
            };
            window.btn_cancel.onclick = function () {
				callback_fn && callback_fn("ok", false);
                close_window();
            };
            window.document.body.focus();
            window.btn_ok.focus();
        </script>
    </body>
</html>